<?php
defined('BY_JYA') or exit('error');

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$fenlei=pdo_getall('core_account_article_fenlei',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$fenleiid=intval($_RQ['fenlei']);
	if($fenleiid){
		$params['fenlei']=$fenleiid;
	}
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$fields=array('id','title','fee','ishot','fenlei','pic_url','keyword','createtime','re_readnum','readnum','likenum','status','content');
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 10;
	}
	$total='';
	$order=intval($_RQ['order']);
	if($order==1){
		$order='id desc';
	}elseif($order==2){
		$order='ishot desc, id desc';
	}else{
		$order='id desc, readnum desc';
	}
	$list=pdo_getslice('core_account_article',$params,array($pindex,$psize),$total,$fields,'',$order);
	if($list){
		foreach($list as &$item){
			$item['content'] = strip_tags(str_replace('&nbsp;','',$item['content']));
			$item['desc'] = $item['desc'] ? $item['desc'] : cfc('tools')->substr($item['content'],0,36);
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['fenlei']=$fenlei[$item['fenlei']]['title'];
			$item['edit']=array('op'=>'edit','action'=>'account.article','query'=>'id='.$item['id']);
			$item['url']=custom_url('core/article.list/detail/id='.$item['id'],true);
			$item['allfee']=pdo_getsum('core_account_article_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'article_id'=>$item['id']),'fee');
		}
	}
	$return['fenleiname']=$fenlei[$fenleiid]['title'];
	$return['list']=$list?$list:array();
	$return['fenlei']=$fenlei?$fenlei:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'文章列表'),
			array('op'=>'edit','action'=>'account.article','title'=>'添加文章'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'文章标题','type'=>'string'),
			array('name'=>'fee','title'=>'费用','type'=>'string'),
			array('name'=>'allfee','title'=>'付费总额','type'=>'string'),
			array('name'=>'fenlei','title'=>'文章分类','type'=>'string'),
			array('name'=>'keyword','title'=>'关键字','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('title'=>'阅读量/点赞量','type'=>'img_string',
			'data'=>array(
				array('title'=>'真实阅读量：','name'=>'re_readnum'),
				array('title'=>'点赞量：','name'=>'likenum')
				)
			),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'ishot','title'=>'是否推荐','type'=>'switch','set'=>'set'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		),'action'=>array(
			array('op'=>'seo_send','title'=>'一键推送','type'=>'modal'),
			array('name'=>'edit','title'=>'编辑','type'=>'href'),
		)),
		'search_one'=>array('name'=>'title','help'=>'','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='seo_send'){
	$return['item']['id']=intval($_RQ['id']);
	$return['item']['jy_sohu']='https://mp.sohu.com/';
	$return['item']['jy_yidianzixun']='https://mp.yidianzixun.com/';
	$return['item']['jy_douyin']='jy_weishop/video.index/';
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'一键推送文章',
		'edit'=>array(
			array('type'=>'tip','title'=>'<red>【温馨提示】：需要移步站点宣传--多媒体--多媒体设置。设置好后，这里才能推送文章！</red>'),
			array('type'=>'switch','title'=>'今日头条推送','name'=>'jy_toutiao'),
			array('type'=>'radio','title'=>'今日头条分类','name'=>'jy_toutiao_fennlei','options'=>'jy_toutiao_fanlei','show'=>array('jy_toutiao'=>1)),
			array('type'=>'switch','title'=>'企鹅号推送','name'=>'jy_qier'),
			array('type'=>'select','title'=>'企鹅号文章分类','name'=>'jy_qier_fenlei','options'=>'jy_qier_fenlei','option_title'=>'name','show'=>array('jy_qier'=>1)),
			array('type'=>'switch','title'=>'熊掌/百家号推送','name'=>'jy_baidu'),
			array('type'=>'switch','title'=>'网易号推送','name'=>'jy_163'),
			array('type'=>'href_url','title'=>'搜狐号推送','name'=>'jy_sohu','btntitle'=>'前往发布','help'=>'搜狐号暂无发布接口，只能手动前往发布！'),
			array('type'=>'href_url','title'=>'一点号推送','name'=>'jy_yidianzixun','btntitle'=>'前往发布','help'=>'一点号暂无发布接口，只能手动前往发布！'),
			array('type'=>'href','title'=>'抖音号推送','url'=>'jy_weishop/video.index/','btntitle'=>'前往发布','help'=>'抖音号推送，目前只支持短视频推送，移步视频管理平台操作！'),
		)
	);
	$return['jy_qier_fenlei']=array(
		array('id'=>1,'name'=>'旅游'),
		array('id'=>2,'name'=>'游戏'),
		array('id'=>4,'name'=>'体育'),
		array('id'=>9,'name'=>'美食'),
		array('id'=>10,'name'=>'健康'),
		array('id'=>13,'name'=>'财经'),
		array('id'=>14,'name'=>'汽车'),
		array('id'=>15,'name'=>'房产'),
		array('id'=>16,'name'=>'动漫'),
		array('id'=>17,'name'=>'教育'),
		array('id'=>18,'name'=>'科技'),
		array('id'=>19,'name'=>'军事'),
		array('id'=>20,'name'=>'天气'),
		array('id'=>21,'name'=>'情感'),
		array('id'=>28,'name'=>'招聘'),
		array('id'=>40,'name'=>'鸡汤'),
		array('id'=>41,'name'=>'社会'),
		array('id'=>42,'name'=>'时政'),
		array('id'=>57,'name'=>'育儿'),
		array('id'=>58,'name'=>'时尚'),
		array('id'=>61,'name'=>'文化'),
		array('id'=>63,'name'=>'宠物'),
		array('id'=>64,'name'=>'互联网'),
		array('id'=>65,'name'=>'数码'),
		array('id'=>69,'name'=>'科学'),
		array('id'=>95,'name'=>'历史'),
		array('id'=>103,'name'=>'摄影'),
		array('id'=>188,'name'=>'搞笑'),
		array('id'=>190,'name'=>'家居'),
		array('id'=>192,'name'=>'美女'),
		array('id'=>194,'name'=>'美图'),
		array('id'=>199,'name'=>'星座'),
		array('id'=>333,'name'=>'健身'),
		array('id'=>182,'name'=>'户外运动'),
		array('id'=>128,'name'=>'NBA'),
		array('id'=>141,'name'=>'CBA'),
		array('id'=>306,'name'=>'新闻'),
	);
	$return['jy_toutiao_fanlei']=array(
		'news_society'=>'社会',
		'news_entertainment'=>'娱乐',
		'movie'=>'电影',
		'news_tech'=>'科技',
		'digital'=>'数码',
		'news_car'=>'汽车',
		'news_sports'=>'体育',
		'news_finance'=>'财经',
		'news_military'=>'军事',
		'news_world'=>'国际',
		'news_fashion'=>'时尚',
		'marvel'=>'奇葩',
		'news_game'=>'游戏',
		'news_travel'=>'旅游',
		'news_baby'=>'育儿',
		'fitness'=>'瘦身',
		'news_regimen'=>'养生',
		'news_food'=>'美食',
		'news_history'=>'历史',
		'news_discovery'=>'探索',
		'news_story'=>'故事',
		'news_essay'=>'美文',
		'emotion'=>'情感',
		'news_health'=>'健康',
		'news_edu'=>'教育',
		'news_home'=>'家居',
		'news_house'=>'房产',
		'funny'=>'搞笑',
		'news_astrology'=>'星座',
		'news_culture'=>'文化',
		'news_pet'=>'宠物',
		'news_law'=>'法制',
		'news_career'=>'职场',
		'comic'=>'漫画',
		'news_comic'=>'动漫',
		'science_all'=>'科学',
		'news_design'=>'设计',
		'news_photography'=>'摄影',
		'news_collect'=>'收藏',
		'news_agriculture'=>'三农',
		'news_psychology'=>'心理',
	);
	if(check_permission('jy_163')){
		//model('jy_163/set_data')->getcategory();
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$id=intval($_RQ['id']);
	$post=get_postdata();
	if(isset($post['ishot'])){
		$update['ishot']=intval($post['ishot']);
	}
	if(isset($post['status'])){
		$update['status']=intval($post['status']);
	}
	if($update){
		pdo_update('core_account_article',$update,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$id=intval($post['id']);
	$news=pdo_get('core_account_article',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$news['content'] = strip_tags(str_replace('&nbsp;','',$news['content']));
	$news['desc'] = $news['desc'] ? $news['desc'] : cfc('tools')->substr($news['content'],0,36);
	$news['url'] =custom_url('core/article.list/detail/id='.$news['id'],true);
	if($post['jy_toutiao'] && check_permission('jy_toutiao')){
		cfc('jy_toutiao')->new_article($news['title'],$news['content'],$news['desc'],1,$post['jy_toutiao_fennlei']);
	}
	if($post['jy_qier'] && check_permission('jy_qier')){
		cfc('jy_qier')->article($news['title'],$news['content'],tomedia($news['pic_url']),$post['jy_qier_fennlei']);
	}
	if($post['jy_baidu'] && check_permission('jy_baidu')){
		model('jy_baidu/set_data')->upnews($news['title'],$news['content'],$news['url'],tomedia($news['pic_url']));
	}
	if($post['jy_163'] && check_permission('jy_163')){
		model('jy_163/set_data')->upnews($news['title'],$news['content'],$post['jy_163_fennlei'],tomedia($news['pic_url']));
	}
	exi('发布成功！');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_account_article',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_account_article',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}